package NewOOP.poly;

class Shape {
    //属性....
    public void draw() {
        System.out.println("画图形！");
    }
}
class Rect extends Shape{
    @Override

    public void draw() {

        System.out.println("画矩形");
    }
}
class Cycle extends Shape{
    @Override
    public void draw() {
        System.out.println("画圆形");
    }

}

class Flower extends Shape {
    @Override
    public void draw() {
        System.out.println("❀");
    }
}

class test {
    public static void drawShapes() {
        // 我们创建了一个 Shape 父类对象的数组.

          //相当于向上转型，比如数组中第一个元素子类Cycle对象的类型是父类Shape类型
        Shape[] shapes = {new Cycle(), new Rect(), new Cycle(),new Rect(), new Flower()};

        for (Shape a : shapes) {
            a.draw();   //调用那个子类，就可以显示出不同的打印(动态绑定）
        }
    }

    public static void main(String[] args) {
        drawShapes();
    }
}

